<template>
  <div id="navTop">
    <div id="logo">
      <!-- <div id="update" @click="getUE"></div> -->
      <div id="time">
        <el-row>
          <el-col :span="12" class="hms">{{ time }}</el-col>
          <el-col :span="12" class="wd">
            <div>{{ week }}</div>
            <div>{{ day }}</div>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      day: undefined,
      week: undefined,
      time: undefined,
      isLabels: false,
    };
  },
  methods: {
    show() {
      // 关闭显示车位
      window.Sgworld.execute("grapi", "BackPark", {}, null);

      // 关闭显示招商信息
      window.Sgworld.execute("grapi", "business", { visibility: false }, null);
    },
    getDate() {
      let date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      month = month < 10 ? "0" + month : month;
      let dates = date.getDate();
      dates = dates < 10 ? "0" + dates : dates;
      let arr = [
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六",
      ];
      let day = date.getDay();
      let hour = date.getHours();
      let min = date.getMinutes();
      min = min < 10 ? "0" + min : min;
      let sed = date.getSeconds();
      sed = sed < 10 ? "0" + sed : sed;
      this.day = year + "." + month + "." + dates;
      this.week = arr[day];
      this.time = hour + ":" + min + ":" + sed + "";
    },
    // 数据更新
    getData() {
      axios.post(window.apiUrl + "/api/queryTree/").then((res) => {
        var tem = res.data.data;
        var vedioArr = [
          { id: "视频1L", label: "1 楼", children: [], rootType: "视频" },
          { id: "视频2L", label: "2 楼", children: [], rootType: "视频" },
          { id: "视频3L", label: "3 楼", children: [], rootType: "视频" },
          { id: "视频4L", label: "4 楼", children: [], rootType: "视频" },
          { id: "视频5L", label: "5 楼", children: [], rootType: "视频" },
          { id: "视频6L", label: "6 楼", children: [], rootType: "视频" },
          { id: "视频B1", label: "B1", children: [], rootType: "视频" },
          { id: "视频B2", label: "B2", children: [], rootType: "视频" },
          { id: "电梯", label: "DT", children: [], rootType: "视频" },
          { id: "室外", label: "SW", children: [], rootType: "视频" },
        ];
        var accessArr = [
          { id: "门禁1L", label: "1 楼", children: [], rootType: "门禁" },
          { id: "门禁2L", label: "2 楼", children: [], rootType: "门禁" },
          { id: "门禁3L", label: "3 楼", children: [], rootType: "门禁" },
          { id: "门禁4L", label: "4 楼", children: [], rootType: "门禁" },
          { id: "门禁5L", label: "5 楼", children: [], rootType: "门禁" },
          { id: "门禁6L", label: "6 楼", children: [], rootType: "门禁" },
          { id: "门禁B1", label: "B1", children: [], rootType: "门禁" },
          { id: "门禁B2", label: "B2", children: [], rootType: "门禁" },
        ];
        var dzxgArr = [
          { id: "电子巡更1L", label: "1 楼", children: [], rootType: "巡更" },
          { id: "电子巡更2L", label: "2 楼", children: [], rootType: "巡更" },
          { id: "电子巡更3L", label: "3 楼", children: [], rootType: "巡更" },
          { id: "电子巡更4L", label: "4 楼", children: [], rootType: "巡更" },
          { id: "电子巡更5L", label: "5 楼", children: [], rootType: "巡更" },
          { id: "电子巡更6L", label: "6 楼", children: [], rootType: "巡更" },
          { id: "电子巡更B1", label: "B1", children: [], rootType: "巡更" },
          { id: "电子巡更B2", label: "B2", children: [], rootType: "巡更" },
        ];
        var tcxtArr = [
          {
            id: "停车系统1L",
            label: "1 楼",
            children: [],
            rootType: "停车系统",
          },
          {
            id: "停车系统2L",
            label: "2 楼",
            children: [],
            rootType: "停车系统",
          },
          {
            id: "停车系统3L",
            label: "3 楼",
            children: [],
            rootType: "停车系统",
          },
          {
            id: "停车系统4L",
            label: "4 楼",
            children: [],
            rootType: "停车系统",
          },
          {
            id: "停车系统5L",
            label: "5 楼",
            children: [],
            rootType: "停车系统",
          },
          {
            id: "停车系统6L",
            label: "6 楼",
            children: [],
            rootType: "停车系统",
          },
          { id: "停车系统B1", label: "B1", children: [], rootType: "停车系统" },
          { id: "停车系统B2", label: "B2", children: [], rootType: "停车系统" },
        ];
        var jjqzArr = [
          {
            id: "紧急求助1L",
            label: "1 楼",
            children: [],
            rootType: "紧急求助",
          },
          {
            id: "紧急求助2L",
            label: "2 楼",
            children: [],
            rootType: "紧急求助",
          },
          {
            id: "紧急求助3L",
            label: "3 楼",
            children: [],
            rootType: "紧急求助",
          },
          {
            id: "紧急求助4L",
            label: "4 楼",
            children: [],
            rootType: "紧急求助",
          },
          {
            id: "紧急求助5L",
            label: "5 楼",
            children: [],
            rootType: "紧急求助",
          },
          {
            id: "紧急求助6L",
            label: "6 楼",
            children: [],
            rootType: "紧急求助",
          },
          { id: "紧急求助B1", label: "B1", children: [], rootType: "紧急求助" },
          { id: "紧急求助B2", label: "B2", children: [], rootType: "紧急求助" },
        ];
        var infoArr = [
          {
            id: "信息发布1L",
            label: "1 楼",
            children: [],
            rootType: "信息发布",
          },
          {
            id: "信息发布2L",
            label: "2 楼",
            children: [],
            rootType: "信息发布",
          },
          {
            id: "信息发布3L",
            label: "3 楼",
            children: [],
            rootType: "信息发布",
          },
          {
            id: "信息发布4L",
            label: "4 楼",
            children: [],
            rootType: "信息发布",
          },
          {
            id: "信息发布5L",
            label: "5 楼",
            children: [],
            rootType: "信息发布",
          },
          {
            id: "信息发布6L",
            label: "6 楼",
            children: [],
            rootType: "信息发布",
          },
          { id: "信息发布B1", label: "B1", children: [], rootType: "信息发布" },
          { id: "信息发布B2", label: "B2", children: [], rootType: "信息发布" },
        ];
        var airArr = [
          { id: "楼控系统1L", label: "1 楼", children: [], rootType: "暖通" },
          { id: "楼控系统2L", label: "2 楼", children: [], rootType: "暖通" },
          { id: "楼控系统3L", label: "3 楼", children: [], rootType: "暖通" },
          { id: "楼控系统4L", label: "4 楼", children: [], rootType: "暖通" },
          { id: "楼控系统5L", label: "5 楼", children: [], rootType: "暖通" },
          { id: "楼控系统6L", label: "6 楼", children: [], rootType: "暖通" },
          { id: "楼控系统B1", label: "B1", children: [], rootType: "暖通" },
          { id: "楼控系统B2", label: "B2", children: [], rootType: "暖通" },
          { id: "楼控系统WD", label: "WD", children: [], rootType: "暖通" },
        ];
        var fireArr = [
          { id: "消防系统1L", label: "1 楼", children: [], rootType: "消防" },
          { id: "消防系统2L", label: "2 楼", children: [], rootType: "消防" },
          { id: "消防系统3L", label: "3 楼", children: [], rootType: "消防" },
          { id: "消防系统4L", label: "4 楼", children: [], rootType: "消防" },
          { id: "消防系统5L", label: "5 楼", children: [], rootType: "消防" },
          { id: "消防系统6L", label: "6 楼", children: [], rootType: "消防" },
          { id: "消防系统B1", label: "B1", children: [], rootType: "消防" },
          { id: "消防系统B2", label: "B2", children: [], rootType: "消防" },
        ];
        var broadArr = [
          { id: "公共广播1L", label: "1 楼", children: [], rootType: "广播" },
          { id: "公共广播2L", label: "2 楼", children: [], rootType: "广播" },
          { id: "公共广播3L", label: "3 楼", children: [], rootType: "广播" },
          { id: "公共广播4L", label: "4 楼", children: [], rootType: "广播" },
          { id: "公共广播5L", label: "5 楼", children: [], rootType: "广播" },
          { id: "公共广播6L", label: "6 楼", children: [], rootType: "广播" },
          { id: "公共广播B1", label: "B1", children: [], rootType: "广播" },
          { id: "公共广播B2", label: "B2", children: [], rootType: "广播" },
        ];
        var zmxtArr = [
          { id: "亮化系统1L", label: "1 楼", children: [], rootType: "照明" },
          { id: "亮化系统2L", label: "2 楼", children: [], rootType: "照明" },
          { id: "亮化系统3L", label: "3 楼", children: [], rootType: "照明" },
          { id: "亮化系统4L", label: "4 楼", children: [], rootType: "照明" },
          { id: "亮化系统5L", label: "5 楼", children: [], rootType: "照明" },
          { id: "亮化系统6L", label: "6 楼", children: [], rootType: "照明" },
          { id: "亮化系统B1", label: "B1", children: [], rootType: "照明" },
          { id: "亮化系统B2", label: "B2", children: [], rootType: "照明" },
        ];
        var dtArr = [
          { id: "电梯系统1L", label: "1 楼", children: [], rootType: "电梯" },
          { id: "电梯系统2L", label: "2 楼", children: [], rootType: "电梯" },
          { id: "电梯系统3L", label: "3 楼", children: [], rootType: "电梯" },
          { id: "电梯系统4L", label: "4 楼", children: [], rootType: "电梯" },
          { id: "电梯系统5L", label: "5 楼", children: [], rootType: "电梯" },
          { id: "电梯系统6L", label: "6 楼", children: [], rootType: "电梯" },
          { id: "电梯系统B1", label: "B1", children: [], rootType: "电梯" },
          { id: "电梯系统B2", label: "B2", children: [], rootType: "电梯" },
        ];
        var bpdArr = [
          {
            id: "变配电系统1L",
            label: "1 楼",
            children: [],
            rootType: "变配电",
          },
          {
            id: "变配电系统2L",
            label: "2 楼",
            children: [],
            rootType: "变配电",
          },
          {
            id: "变配电系统3L",
            label: "3 楼",
            children: [],
            rootType: "变配电",
          },
          {
            id: "变配电系统4L",
            label: "4 楼",
            children: [],
            rootType: "变配电",
          },
          {
            id: "变配电系统5L",
            label: "5 楼",
            children: [],
            rootType: "变配电",
          },
          {
            id: "变配电系统6L",
            label: "6 楼",
            children: [],
            rootType: "变配电",
          },
          { id: "变配电系统B1", label: "B1", children: [], rootType: "变配电" },
          { id: "变配电系统B2", label: "B2", children: [], rootType: "变配电" },
        ];
        var rqArr = [
          { id: "人脸识别系统1L", label: "1 楼", children: [], rootType: "入侵" },
          { id: "人脸识别系统2L", label: "2 楼", children: [], rootType: "入侵" },
          { id: "人脸识别系统3L", label: "3 楼", children: [], rootType: "入侵" },
          { id: "人脸识别系统4L", label: "4 楼", children: [], rootType: "入侵" },
          { id: "人脸识别系统5L", label: "5 楼", children: [], rootType: "入侵" },
          { id: "人脸识别系统6L", label: "6 楼", children: [], rootType: "入侵" },
          { id: "人脸识别系统B1", label: "B1", children: [], rootType: "入侵" },
          { id: "人脸识别系统B2", label: "B2", children: [], rootType: "入侵" },
        ];

        window.Sgworld.execute("grapi", "GetALL", {}, (e) => {
          for (var i = 0; i < tem.length; i++) {
            if (tem[i].code == e.args.name) {
              e.args = { ...e.args, ...tem[i] };
            }
          }
          // 设备所在楼层
          var LC = e.args.code ? e.args.code.substring(0, 2) : "无";
          // 设备的名称
          var MX = e.args.code ? e.args.code.substring(3) : "无";
          // 设备所在的位置
          var rotation = { roll: 0, pitch: 0, yaw: 0 };
          var tposition = { ...e.args.location, ...rotation };
          var item = {
            id: MX,
            label: MX,
            floorId: LC,
            name: e.args.name,
            pid: e.args.pid,
            code: e.args.code,
            buildName: "展示中心大楼",
            position: tposition,
          };
          if (e.args.code) {
            if (
              e.args.code.indexOf("摄像") != -1 ||
              e.args.code.indexOf("QXSXT") != -1
            ) {
              item.rootType = "视频";
              LC == "1F" && vedioArr[0].children.push(item);
              LC == "2F" && vedioArr[1].children.push(item);
              LC == "3F" && vedioArr[2].children.push(item);
              LC == "4F" && vedioArr[3].children.push(item);
              LC == "5F" && vedioArr[4].children.push(item);
              LC == "6F" && vedioArr[5].children.push(item);
              LC == "B1" && vedioArr[6].children.push(item);
              LC == "B2" && vedioArr[7].children.push(item);
              LC == "DT" && vedioArr[8].children.push(item);
              (LC == "WD" || LC == "SW") && vedioArr[9].children.push(item);
              get_data[0].children[0].children = vedioArr;
            }
            if (e.args.code.indexOf("门禁") != -1) {
              item.rootType = "门禁";
              LC == "1F" && accessArr[0].children.push(item);
              LC == "2F" && accessArr[1].children.push(item);
              LC == "3F" && accessArr[2].children.push(item);
              LC == "4F" && accessArr[3].children.push(item);
              LC == "5F" && accessArr[4].children.push(item);
              LC == "6F" && accessArr[5].children.push(item);
              LC == "B1" && accessArr[6].children.push(item);
              LC == "B2" && accessArr[7].children.push(item);
              get_data[0].children[1].children = accessArr;
            }
            if (e.args.code.indexOf("信息发布") != -1) {
              item.rootType = "信息发布";
              LC == "1F" && infoArr[0].children.push(item);
              LC == "2F" && infoArr[1].children.push(item);
              LC == "3F" && infoArr[2].children.push(item);
              LC == "4F" && infoArr[3].children.push(item);
              LC == "5F" && infoArr[4].children.push(item);
              LC == "6F" && infoArr[5].children.push(item);
              LC == "B1" && infoArr[6].children.push(item);
              LC == "B2" && infoArr[7].children.push(item);
              get_data[0].children[6].children = infoArr;
            }
            if (
              e.args.code.indexOf("XF") != -1 ||
              e.args.code.indexOf("AHU") != -1 ||
              e.args.code.indexOf("PF") != -1
            ) {
              item.rootType = "暖通";
              LC == "1F" && airArr[0].children.push(item);
              LC == "2F" && airArr[1].children.push(item);
              LC == "3F" && airArr[2].children.push(item);
              LC == "4F" && airArr[3].children.push(item);
              LC == "5F" && airArr[4].children.push(item);
              LC == "6F" && airArr[5].children.push(item);
              LC == "B1" && airArr[6].children.push(item);
              LC == "B2" && airArr[7].children.push(item);
              LC == "WD" && airArr[8].children.push(item);
              get_data[0].children[7].children = airArr;
            }
            if (
              e.args.code.indexOf("消防") != -1 ||
              e.args.code.indexOf("报警器") != -1 ||
              (e.args.code.indexOf("灭火装置") != -1 &&
                e.args.code.indexOf("残卫") == -1)
            ) {
              item.rootType = "消防";
              LC == "1F" && fireArr[0].children.push(item);
              LC == "2F" && fireArr[1].children.push(item);
              LC == "3F" && fireArr[2].children.push(item);
              LC == "4F" && fireArr[3].children.push(item);
              LC == "5F" && fireArr[4].children.push(item);
              LC == "6F" && fireArr[5].children.push(item);
              LC == "B1" && fireArr[6].children.push(item);
              LC == "B2" && fireArr[7].children.push(item);
              get_data[0].children[8].children = fireArr;
            }
            if (e.args.code.indexOf("喇叭") != -1) {
              item.rootType = "广播";
              LC == "1F" && broadArr[0].children.push(item);
              LC == "2F" && broadArr[1].children.push(item);
              LC == "3F" && broadArr[2].children.push(item);
              LC == "4F" && broadArr[3].children.push(item);
              LC == "5F" && broadArr[4].children.push(item);
              LC == "6F" && broadArr[5].children.push(item);
              LC == "B1" && broadArr[6].children.push(item);
              LC == "B2" && broadArr[7].children.push(item);
              get_data[0].children[5].children = broadArr;
            }
            if (e.args.code.indexOf("巡检点") != -1) {
              item.rootType = "巡更";
              LC == "1F" && dzxgArr[0].children.push(item);
              LC == "2F" && dzxgArr[1].children.push(item);
              LC == "3F" && dzxgArr[2].children.push(item);
              LC == "4F" && dzxgArr[3].children.push(item);
              LC == "5F" && dzxgArr[4].children.push(item);
              LC == "6F" && dzxgArr[5].children.push(item);
              LC == "B1" && dzxgArr[6].children.push(item);
              LC == "B2" && dzxgArr[7].children.push(item);
              get_data[0].children[2].children = dzxgArr;
            }
            if (
              e.args.code.indexOf("车位") != -1 ||
              e.args.code.indexOf("查询一体机") != -1 ||
              e.args.code.indexOf("引导显示屏") != -1
            ) {
              item.rootType = "停车系统";
              LC == "1F" && tcxtArr[0].children.push(item);
              LC == "2F" && tcxtArr[1].children.push(item);
              LC == "3F" && tcxtArr[2].children.push(item);
              LC == "4F" && tcxtArr[3].children.push(item);
              LC == "5F" && tcxtArr[4].children.push(item);
              LC == "6F" && tcxtArr[5].children.push(item);
              LC == "B1" && tcxtArr[6].children.push(item);
              LC == "B2" && tcxtArr[7].children.push(item);
              get_data[0].children[3].children = tcxtArr;
            }
            if (e.args.code.indexOf("残卫") != -1) {
              item.rootType = "紧急求助";
              LC == "1F" && jjqzArr[0].children.push(item);
              LC == "2F" && jjqzArr[1].children.push(item);
              LC == "3F" && jjqzArr[2].children.push(item);
              LC == "4F" && jjqzArr[3].children.push(item);
              LC == "5F" && jjqzArr[4].children.push(item);
              LC == "6F" && jjqzArr[5].children.push(item);
              LC == "B1" && jjqzArr[6].children.push(item);
              LC == "B2" && jjqzArr[7].children.push(item);
              get_data[0].children[4].children = jjqzArr;
            }
            if (e.args.code.indexOf("灯") != -1) {
              item.rootType = "照明";
              LC == "1F" && zmxtArr[0].children.push(item);
              LC == "2F" && zmxtArr[1].children.push(item);
              LC == "3F" && zmxtArr[2].children.push(item);
              LC == "4F" && zmxtArr[3].children.push(item);
              LC == "5F" && zmxtArr[4].children.push(item);
              LC == "6F" && zmxtArr[5].children.push(item);
              LC == "B1" && zmxtArr[6].children.push(item);
              LC == "B2" && zmxtArr[7].children.push(item);
              get_data[0].children[9].children = zmxtArr;
            }
            if (e.args.code.indexOf("电梯") != -1) {
              item.rootType = "电梯";
              LC == "1F" && dtArr[0].children.push(item);
              LC == "2F" && dtArr[1].children.push(item);
              LC == "3F" && dtArr[2].children.push(item);
              LC == "4F" && dtArr[3].children.push(item);
              LC == "5F" && dtArr[4].children.push(item);
              LC == "6F" && dtArr[5].children.push(item);
              LC == "B1" && dtArr[6].children.push(item);
              LC == "B2" && dtArr[7].children.push(item);
              get_data[0].children[10].children = dtArr;
            }
            if (
              e.args.code.indexOf("变配电") != -1 ||
              e.args.code.indexOf("强电室") != -1
            ) {
              item.rootType = "变配电";
              LC == "1F" && bpdArr[0].children.push(item);
              LC == "2F" && bpdArr[1].children.push(item);
              LC == "3F" && bpdArr[2].children.push(item);
              LC == "4F" && bpdArr[3].children.push(item);
              LC == "5F" && bpdArr[4].children.push(item);
              LC == "6F" && bpdArr[5].children.push(item);
              LC == "B1" && bpdArr[6].children.push(item);
              LC == "B2" && bpdArr[7].children.push(item);
              get_data[0].children[11].children = bpdArr;
            }
          }
          count++;
          console.log(count);
          if (count > 10000) {
            console.log(JSON.stringify(get_data));
          }
        });
      });
    },

    getUE() {
      var a = [];
      var num = 0;
      window.Sgworld.execute("grapi", "GetALL", {}, (e) => {
        // console.log(e.args.name);
        var item = JSON.parse(JSON.stringify(e.args));
        num++;
        a.push(item);
        console.log(num);
        if (num > 10200) {
          console.log(JSON.stringify(a));
        }
      });
    },

    // 测试
  },
  mounted() {
    this.getDate();
    setInterval(this.getDate, 1000);
  },
};
</script>
<style scoped>
#navTop,
#logo {
  height: 160px;
  background: url("../../../static/images/topBackground.png") no-repeat center;
  background-size: 100% 100%;
}
#logo {
  background: url("../../../static/images/logo.png");
  cursor: pointer;
}
#update {
  float: left;
  background: url("../../../static/images/modules/update.png") no-repeat center;
  background-size: 100% 100%;
  line-height: 60px;
  margin-left: 120px;
  margin-top: 60px;
  height: 60px;
  width: 60px;
}
#time {
  color: white;
  float: right;
  line-height: 70px;
  margin-right: 120px;
  margin-top: 60px;
  height: 70px;
  width: 400px;
}
#time .hms {
  color: #1cadf1;
  font-size: 60px;
  font-family: "AgencyFB";
  text-align: center;
}
#time .wd {
  height: 35px;
  line-height: 35px;
  font-size: 24px;
}
</style>
